/*     */ package com.zimbra.cs.server;
/*     */ 
/*     */ import com.google.common.base.Charsets;
/*     */ import com.zimbra.common.util.Log;
/*     */ import java.io.IOException;
/*     */ import org.apache.mina.core.buffer.IoBuffer;
/*     */ import org.apache.mina.core.service.IoHandlerAdapter;
/*     */ import org.apache.mina.core.session.IdleStatus;
/*     */ import org.apache.mina.core.session.IoSession;
/*     */ import org.apache.mina.filter.codec.ProtocolDecoderException;
/*     */ import org.apache.mina.transport.socket.nio.ZimbraSocketAcceptor;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ final class NioHandlerDispatcher
/*     */   extends IoHandlerAdapter
/*     */ {
/*     */   private final NioServer server;
/*     */   
/*     */   NioHandlerDispatcher(NioServer server)
/*     */   {
/*  38 */     this.server = server;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void sessionCreated(IoSession session)
/*     */     throws IOException
/*     */   {
/*  49 */     NioConnection conn = new NioConnection(this.server, session);
/*  50 */     session.setAttribute(NioConnection.class, conn);
/*  51 */     session.setAttribute(NioHandler.class, this.server.createHandler(conn));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void sessionOpened(IoSession session)
/*     */     throws IOException
/*     */   {
/*  61 */     NioHandler handler = getHandler(session);
/*  62 */     if (!this.server.config.isServiceEnabled()) {
/*  63 */       this.server.getLog().warn("Dropping connection (user services are disabled)");
/*  64 */       session.close(true);
/*  65 */     } else if (this.server.acceptor.getManagedSessionCount() > this.server.getConfig().getMaxConnections()) {
/*  66 */       this.server.getLog().warn("Dropping connection (max connections exceeded)");
/*  67 */       String message = this.server.getConfig().getConnectionRejected();
/*  68 */       if (message != null) {
/*  69 */         session.write(IoBuffer.wrap((message + "\r\n").getBytes(Charsets.ISO_8859_1)));
/*     */       }
/*  71 */       session.close(false);
/*     */     } else {
/*  73 */       handler.connectionOpened();
/*     */     }
/*     */   }
/*     */   
/*     */   public void sessionClosed(IoSession session) throws IOException
/*     */   {
/*  79 */     getHandler(session).connectionClosed();
/*  80 */     getConnection(session).close();
/*     */   }
/*     */   
/*     */   public void sessionIdle(IoSession session, IdleStatus status) throws IOException
/*     */   {
/*  85 */     getHandler(session).connectionIdle();
/*     */   }
/*     */   
/*     */   public void messageReceived(IoSession session, Object msg) throws IOException, ProtocolDecoderException
/*     */   {
/*  90 */     NioConnection conn = getConnection(session);
/*  91 */     if ((conn != null) && (!conn.isTlsStartedIfNecessary())) {
/*  92 */       this.server.getLog().warn("plaintext message received during starttls handshake");
/*  93 */       return;
/*     */     }
/*  95 */     getHandler(session).messageReceived(msg);
/*     */   }
/*     */   
/*     */   public void exceptionCaught(IoSession session, Throwable e) throws IOException
/*     */   {
/* 100 */     getHandler(session).exceptionCaught(e);
/*     */   }
/*     */   
/*     */   public static NioHandler getHandler(IoSession session) {
/* 104 */     return (NioHandler)session.getAttribute(NioHandler.class);
/*     */   }
/*     */   
/*     */   public static NioConnection getConnection(IoSession session) {
/* 108 */     return (NioConnection)session.getAttribute(NioConnection.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/server/NioHandlerDispatcher.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */